package pl.edu.agh.experts.diseases;

import java.text.DecimalFormat;
import java.util.List;

import pl.edu.agh.experts.diseases.commons.IDisease;
import pl.edu.agh.experts.diseases.commons.MetaKnowledge;
import pl.edu.agh.experts.diseases.commons.Symptom;

public class Printer {

	private static String roundDecimal(double value) {
		return new DecimalFormat("0.00000").format(value);
	}

	private static String addPad(String text, int length) {
		StringBuffer str = new StringBuffer(text);
		while (str.length() < length) {
			str.append(" ");
		}
		return str.toString();
	}
	
	public static String getResults(List<IDisease> diseases) {
		StringBuffer sb = new StringBuffer("\n\nWyniki badania:\n");
		while (diseases.size() > 0) {
			int bestFit = 0;
			for (int i = 0; i < diseases.size(); i++) {
				if (diseases.get(i).getWeight() > diseases.get(bestFit).getWeight()) {
					bestFit = i;
				}
			}
			IDisease disease = diseases.get(bestFit);
			diseases.remove(bestFit);
			sb.append(addPad(disease.getName(), 35)
					+ roundDecimal(disease.getWeight())+"\n");
		}
		return sb.toString();
	}

	public static void printResults(List<IDisease> diseases) {
		System.out.println(getResults(diseases));
	}

	public static void printMetaQuestion(MetaKnowledge metaKnowledge) {
		System.out.println("\n" + metaKnowledge.getQuestion());
	}

	public static void printSymptomQuestion(Symptom symptom) {
		System.out.println("\n" + symptom.getQuestion());
	}

}
